package com.isoft.c2team3service2.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.isoft.c2team3service2.entity.UserMessageStatus;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMessageStatusMapper extends BaseMapper<UserMessageStatus> {
    // 修复：IN (#{messageIds}) → IN (#{messageIds}) 需改为 IN (#{messageIds}) + @Param注解
    @Update("UPDATE user_message_status SET is_read = 1 WHERE receiver_id = #{receiverId} AND message_id IN (#{messageIds})")
    int batchMarkAsRead(@Param("receiverId") Integer receiverId, @Param("messageIds") List<Integer> messageIds);
    // 新增：查询当前用户的未读消息总数
    @Select("SELECT COUNT(1) FROM user_message_status WHERE receiver_id = #{receiverId} AND is_read = 0")
    Integer countUnreadByReceiverId(@Param("receiverId") Integer receiverId);
}